package com.course.cdspringboot.controller.achievement;


import com.course.cdspringboot.mapper.achievement.AchievementsMapper;
import com.course.cdspringboot.security.RoleAccessControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/api/achievement")
public class AchievementsController {

    @Autowired
    private AchievementsMapper achievementsMapper;

    @Autowired
    RoleAccessControl roleAccessControl;

    /* 插入成果 */

//    // 学生插入专利
//    @Transactional
//    @PostMapping("/insert_patent")
//    public void addAchievementPatent(@RequestBody Map<String, Object> achievementPatent) {
//        Map<String, Object> role = roleAccessControl.checkAccess("ROLE_STUDENT");
//        Map<String, Object> insertInfo = new HashMap<>();
//
//        insertInfo.put("owner", role.get("uid"));
//        insertInfo.put("achievement_type_id", 2); // 假设专利类型 ID 为 2
//        insertInfo.put("achievement_id", null);
//
//        achievementsMapper.insertAchievements(insertInfo);
//        achievementPatent.put("achievement_id", insertInfo.get("achievement_id"));
//        achievementsMapper.insertAchievementPatent(achievementPatent);
//    }



//    // 学生更新专利
//    @PutMapping("/update_patent")
//    public void updateAchievementPatent(@RequestBody Map<String, Object> achievement_patent) {
//        Map<String, Object> role = roleAccessControl.checkAccess("ROLE_STUDENT");
//        achievement_patent.put("uid", role.get("uid"));
//        achievementsMapper.updatePatent(achievement_patent);
//    }



//    // 学生删除 patent
//    @DeleteMapping("/delete_patent")
//    public void deleteAchievementPatent(@RequestBody Map<String, Object> params) {
//        Map<String, Object> role = roleAccessControl.checkAccess("ROLE_STUDENT");
//        params.put("uid", role.get("uid"));
//        achievementsMapper.deleteAchievement(params);
//    }



    /* 学生查询 */
    // 学生查询论文


//    // 学生查询专利
//    @GetMapping("/patent")
//    List<Map<String, Object>> studentGetPatent() {
//        Map<String, Object> role = roleAccessControl.checkAccess("ROLE_STUDENT");
//        return achievementsMapper.studentGetAchievement((Long) role.get("uid"), "achievement_patent");
//    }
//
//    // 学生查询学术交流
//    @GetMapping("/academic_exchange")
//    List<Map<String, Object>> studentGetAcademicExchange() {
//        Map<String, Object> role = roleAccessControl.checkAccess("ROLE_STUDENT");
//        return achievementsMapper.studentGetAchievement((Long) role.get("uid"), "achievement_academic_exchange");
//    }



//    /* 教师查询 */
//    // 教师获取论文
//    @GetMapping("/students_paper")
//    List<Map<String, Object>> teacherGetPaper() {
//        Map<String, Object> role = roleAccessControl.checkAccess("ROLE_TEACHER");
//        return achievementMapper.teacherGetAchievement((Long) role.get("uid"));
//    }
//
//    // 教师获取学生的专利
//    @GetMapping("/students_patent")
//    List<Map<String, Object>> teacherGetPatent() {
//        Map<String, Object> role = roleAccessControl.checkAccess("ROLE_TEACHER");
//        return achievementMapper.teacher_get_patent((Long) role.get("uid"));
//    }
//
//    // 教师获取学生的学术交流
//    @GetMapping("/students_academic_exchange")
//    List<Map<String, Object>> teacherGetAcademicExchange() {
//        Map<String, Object> role = roleAccessControl.checkAccess("ROLE_TEACHER");
//        return achievementMapper.teacher_get_academic_exchange((Long) role.get("uid"));
//    }

}
